﻿/**************************************************************************
创建日期:	2019/7/23
作	  者:	张存
邮 	  箱:	zhangcunliang@126.com
创建时间:	
Copyright (c)   zhcun.cn

描	述：
记	录：
***************************************************************************/
using System;
using ZhCun.RightsManage.DBModel;
using ZhCun.Utils;
using ZhCun.Utils.Helpers;
using ZhCun.WebUtils.DB;
using ZhCun.WebUtils.VModel;

namespace ZhCun.RightsManage.AL
{
    public class Log_GetArg : ArgGetList
    {
        public DateTime? StartTime { set; get; }

        public DateTime? EndTime { set; get; }

        public string UserName { set; get; }

        public int? StatusCode { set; get; }

        public string HttpMethod { set; get; }

    }

    public class LogBLL : BLLBase
    {
        public ApiResultList<Sys_LogHttp> GetHttpList(Log_GetArg arg)
        {
            var rList =
            GetPagerList<Sys_LogHttp>(arg.page, arg.limit, out int total, query =>
            {
                if (arg.StartTime == null)
                {
                    arg.StartTime = DateTime.Now.ToDateFormat();
                }
                if (arg.EndTime == null)
                {
                    arg.EndTime = DateTime.Now.ToDateFormat(1);
                }
                if (arg.StatusCode != null)
                {
                    query.WhereAnd(s => s.StatusCode == arg.StatusCode);
                }
                if (!string.IsNullOrWhiteSpace(arg.HttpMethod))
                {
                    query.WhereAnd(s => s.HttpMethod == arg.HttpMethod);
                }
                if (!string.IsNullOrWhiteSpace(arg.UserName))
                {
                    string likeStr = $"%{arg.UserName}%";
                    query.WhereAnd(s => s.WEx_Like(s.UserName, arg.UserName));
                }
                query.WhereAnd(s => s.AddTime >= arg.StartTime && s.AddTime <= arg.EndTime);
                //if (!string.IsNullOrWhiteSpace(arg.searchValue))
                //{
                //    string likeStr = $"%{arg.searchValue}%";
                //    query.WhereAnd(s => s.WEx_Like(s.RequestContent, likeStr));
                //}
                query.OrderBy(s => s.AddTime, DbCore.EmQueryOrder.Desc);
            });

            return this.RetOK(rList, total);
        }
    }
}